Meeting Rooms II

Medium

Extra practice. This problem has no walkthrough slides. Try solving it with the pattern template on your own, and lean on the hints if you get stuck.

Question

You're given intervals, a list of booking times for a shared conference room, where each entry is [start, end]. Any two bookings that overlap need their own separate room. Return the fewest rooms you'd need to book so that every meeting has a room at the same time it's scheduled.

Input: intervals = [[0, 30], [5, 10], [15, 20]]

Output: 2

[5, 10] and [15, 20] both fall inside [0, 30], but they don't overlap each other, so one room can host both of them while a second room hosts [0, 30].

Input: intervals = [[7, 10], [2, 4]]

Output: 1

Neither booking overlaps the other, so one room covers both.

Input: intervals = [[1, 4], [4, 5]]

Output: 1

The first booking ends exactly when the second one begins, so the room is free in time and only one room is needed.

Clarify the problem

What are some questions you'd ask an interviewer?

Understand the problem

How many rooms are needed for this booking list? intervals = [[1, 5], [2, 6], [3, 7], [4, 8]]
1
2
4
0

Take a moment to understand the problem and think of your approach before you start coding.